package models

//物品表
type Company struct {
	Company string `gorm:"column:company"`
	Comno   string `gorm:"column:comno"`
}

func GetAllCompany(CompanyParam map[string]interface{}) (error, []Company, int64) {
	var companyData []Company
	page := CompanyParam["page"].(int)
	pageSize := CompanyParam["limit"].(int)
	searchText := CompanyParam["searchText"].(string)
	var total int64
	err := db.Table("company").Where("company like ?", "%"+searchText+"%").Order("comno ASC").Count(&total).Find(&companyData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, companyData, total
}
func AddCompany(companydata Company) (error, Company) {
	err := db.Table("company").Select("company", "comno").Create(&companydata).Error
	return err, companydata
}

func UpdateCompany(company string, companydata Company) (error, Company) {
	err := db.Table("company").Where("company = ?", companydata.Company).Updates(&companydata).Error
	return err, companydata
}

func DeleteCompany(company string) (error, Company) {
	var companydata Company
	companydata.Company = company
	err := db.Table("company").Where("company = ?", company).Find(&companydata).Delete(Company{}).Error
	return err, companydata
}
